package com.sqxgg.drugstore.threadPool.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

@Component
public class ListenPool {

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

    @Scheduled(cron="*/5 * * * * ?")

    public void scheduledFixedRate() {

        ThreadPoolTaskExecutor paymentTaskExexutor = ThreadPoolInfoUtil.threadPoolMap.get("TaskExecutor");
        ThreadPoolExecutor threadPoolExecutor = paymentTaskExexutor.getThreadPoolExecutor();
        long activeCount = threadPoolExecutor.getActiveCount();

            String threadNamePrefix = paymentTaskExexutor.getThreadNamePrefix();
            long taskCount = threadPoolExecutor.getTaskCount();
            long poolSize = threadPoolExecutor.getPoolSize();
            long completedTaskCount = threadPoolExecutor.getCompletedTaskCount();
            long queueSize = threadPoolExecutor.getQueue().size();
            log.info("threadNamePrefix=>{}, taskCount=>{}, completedTaskCount=>{}, activeCount=>{}, queueSize=>{}",
                    threadNamePrefix, taskCount, completedTaskCount, activeCount, queueSize);



    }
}
